--
-- Author: mengjie
-- Date: 2016-04-09 15:27:19
--
local GameScene = import(".GameScene")
local LoginScene = class("LoginScene", function()
    return display.newScene("LoginScene")
end)
function LoginScene:ctor()
	self:setNodeEventEnabled(true)
	local cellWidth = math.ceil((display.width-2)/2)
	local cellHeight = math.ceil((display.height-2)/2) 
	local block
	local blockColor={ {6,7},
					   {7,6}}
	for y=1,2 do
		for i=1,2 do
			block = display.newSprite("#boom"..blockColor[y][i]..".png", cellWidth*(i-1)+i,(y-1)*cellHeight+y):addTo(self)
			block:setAnchorPoint(cc.p(0,0))
			block:setContentSize(cc.size(cellWidth, cellHeight))
			block:setScaleX(cellWidth)
			block:setScaleY(cellHeight)
		end
	end

	local label = display.newTTFLabel({
	    text = "经典",
	    size = 64,
	    color = display.COLOR_BLACK,
	    align = cc.TEXT_ALIGNMENT_CENTER
	})
	label:setPosition(display.width/4, 3*display.height/4)
	self:addChild(label)

	local label = display.newTTFLabel({
	    text = "街机",
	    size = 64,
	    align = cc.TEXT_ALIGNMENT_CENTER
	})
	label:setPosition(3*display.width/4, 3*display.height/4)
	self:addChild(label)

	local label = display.newTTFLabel({
	    text = "禅",
	    size = 64,
	    align = cc.TEXT_ALIGNMENT_CENTER
	})
	label:setPosition(display.width/4, display.height/4)
	self:addChild(label)

	local label = display.newTTFLabel({
	    text = "设置",
	    size = 64,
	    color = display.COLOR_BLACK,
	    align = cc.TEXT_ALIGNMENT_CENTER
	})
	label:setPosition(3*display.width/4, display.height/4)
	self:addChild(label)
end
function LoginScene:onEnter()
	self:setEventListener()
end
function LoginScene:setEventListener()
   
    local listener = cc.EventListenerTouchAllAtOnce:create()
    listener:registerScriptHandler(function(touchs, event) 
      
    end, cc.Handler.EVENT_TOUCHES_BEGAN  )

    listener:registerScriptHandler(function(touchs, event)
        
    end, cc.Handler.EVENT_TOUCHES_MOVED)

    listener:registerScriptHandler(function(touchs, event) 
         if #touchs ~= 0 then
           
            local location = touchs[1]:getLocationInView()            
			if location.x <display.cx then
				if location.y < display.cy then
					-- 金典
					changeScene("GameScene")
				else
					-- 禅
					changeScene("ChanGameScene")
				end
			else 
				if location.y < display.cy then
					-- 接机
					changeScene("ArcadegameScene")
				else
					-- 设置
					changeScene("SetingScene")
				end
			end
        end
    end, cc.Handler.EVENT_TOUCHES_ENDED)

    local eventDispatcher = self:getEventDispatcher()
    eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)
end
return LoginScene